#ifndef ANAGRAM_OPTIMIZER_NGRAMTOOL_NGRAM_H
#define ANAGRAM_OPTIMIZER_NGRAMTOOL_NGRAM_H

#include <functional>

#include "istring.h"

namespace anagram_optimizer {

// Storage for an n-gram.
template<int N>
struct NGram {
  istring words[N];

  bool operator ==(const NGram<N>& other) const {
    for (int i = 0; i < N; ++i) {
      if (words[i] != other.words[i]) {
        return false;
      }
    }
    return true;
  }
};

}  // namespace anagram_optimizer

namespace std {
template<int N> struct hash<anagram_optimizer::NGram<N>> {
  size_t operator()(const anagram_optimizer::NGram<N>& g) const {
    std::hash<anagram_optimizer::istring> h;
    size_t ret = h(g.words[0]);
    for (int i = 1; i < N; ++i) {
      ret ^= h(g.words[i]);
    }
    return ret;
  }
};
}  // namespace std

#endif  // ANAGRAM_OPTIMIZER_NGRAMTOOL_NGRAM_H
